home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / ambush.c < prev    next >
C/C++ Source or Header  |  2000-03-03  |  4KB  |  183 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. unsigned char *ambush_scrollram;
  14. unsigned char *ambush_colorbank;
  15.  
  16.  
  17. /***************************************************************************
  18.  
  19.   Convert the color PROMs into a more useable format.
  20.  
  21.   I'm not sure about the resistor value, I'm using the Galaxian ones.
  22.  
  23. ***************************************************************************/
  24. void ambush_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  25. {
  26.     int i;
  27.  
  28.     /* first, the char acter/sprite palette */
  29.     for (i = 0;i < Machine->drv->total_colors; i++)
  30.     {
  31.         int bit0,bit1,bit2;
  32.  
  33.         /* red component */
  34.         bit0 = (*color_prom >> 0) & 0x01;
  35.         bit1 = (*color_prom >> 1) & 0x01;
  36.         bit2 = (*color_prom >> 2) & 0x01;
  37.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  38.         /* green component */
  39.         bit0 = (*color_prom >> 3) & 0x01;
  40.         bit1 = (*color_prom >> 4) & 0x01;
  41.         bit2 = (*color_prom >> 5) & 0x01;
  42.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  43.         /* blue component */
  44.         bit0 = 0;
  45.         bit1 = (*color_prom >> 6) & 0x01;
  46.         bit2 = (*color_prom >> 7) & 0x01;
  47.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  48.  
  49.         color_prom++;
  50.     }
  51. }
  52.  
  53.  
  54. /***************************************************************************
  55.  
  56.   Draw the game screen in the given osd_bitmap.
  57.   Do NOT call osd_update_display() from this function, it will be called by
  58.   the main emulation engine.
  59.  
  60. ***************************************************************************/
  61.  
  62. static void draw_chars(struct osd_bitmap *bitmap, int priority)
  63. {
  64.     int offs, transparency;
  65.  
  66.  
  67.     transparency = (priority == 0) ? TRANSPARENCY_NONE : TRANSPARENCY_PEN;
  68.  
  69.     for (offs = 0; offs < videoram_size; offs++)
  70.     {
  71.         int code,sx,sy,col;
  72.         UINT8 scroll;
  73.  
  74.  
  75.         sy = (offs / 32);
  76.         sx = (offs % 32);
  77.  
  78.         col = colorram[((sy & 0x1c) << 3) + sx];
  79.  
  80.         if ((col & 0x10) != priority)  continue;
  81.  
  82.         scroll = ~ambush_scrollram[sx];
  83.  
  84.         code = videoram[offs] | ((col & 0x60) << 3);
  85.  
  86.         if (*flip_screen)
  87.         {
  88.             sx = 31 - sx;
  89.             sy = 31 - sy;
  90.             scroll = ~scroll - 1;
  91.         }
  92.  
  93.         drawgfx(bitmap,Machine->gfx[0],
  94.                 code,
  95.                 (col & 0x0f) | ((*ambush_colorbank & 0x03) << 4),
  96.                 *flip_screen,*flip_screen,
  97.                 8*sx, (8*sy + scroll) & 0xff,
  98.                 &Machine->drv->visible_area,transparency,0);
  99.     }
  100. }
  101.  
  102.  
  103. void ambush_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  104. {
  105.     int offs;
  106.  
  107.  
  108.     fillbitmap(bitmap,Machine->pens[0],&Machine->drv->visible_area);
  109.  
  110.  
  111.     /* Draw the background priority characters */
  112.     draw_chars(bitmap, 0x00);
  113.  
  114.  
  115.     /* Draw the sprites. */
  116.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  117.     {
  118.         int code,col,sx,sy,flipx,flipy,gfx;
  119.  
  120.  
  121.         sy = spriteram[offs + 0];
  122.         sx = spriteram[offs + 3];
  123.  
  124.         if ( (sy == 0) ||
  125.              (sy == 0xff) ||
  126.             ((sx <  0x40) && (  spriteram[offs + 2] & 0x10)) ||
  127.             ((sx >= 0xc0) && (!(spriteram[offs + 2] & 0x10))))  continue;  /* prevent wraparound */
  128.  
  129.  
  130.         code = (spriteram[offs + 1] & 0x3f) | ((spriteram[offs + 2] & 0x60) << 1);
  131.  
  132.         if (spriteram[offs + 2] & 0x80)
  133.         {
  134.             /* 16x16 sprites */
  135.             gfx = 1;
  136.  
  137.             if (!*flip_screen)
  138.             {
  139.                 sy = 240 - sy;
  140.             }
  141.             else
  142.             {
  143.                 sx = 240 - sx;
  144.             }
  145.         }
  146.         else
  147.         {
  148.             /* 8x8 sprites */
  149.             gfx = 0;
  150.             code <<= 2;
  151.  
  152.             if (!*flip_screen)
  153.             {
  154.                 sy = 248 - sy;
  155.             }
  156.             else
  157.             {
  158.                 sx = 248 - sx;
  159.             }
  160.         }
  161.  
  162.         col   = spriteram[offs + 2] & 0x0f;
  163.         flipx = spriteram[offs + 1] & 0x40;
  164.         flipy = spriteram[offs + 1] & 0x80;
  165.  
  166.         if (*flip_screen)
  167.         {
  168.             flipx = !flipx;
  169.             flipy = !flipy;
  170.         }
  171.  
  172.         drawgfx(bitmap,Machine->gfx[gfx],
  173.                 code, col | ((*ambush_colorbank & 0x03) << 4),
  174.                 flipx, flipy,
  175.                 sx,sy,
  176.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  177.     }
  178.  
  179.  
  180.     /* Draw the foreground priority characters */
  181.     draw_chars(bitmap, 0x10);
  182. }
  183.